package cn.edu.zzuli.wechat.user.controller;

import cn.edu.zzuli.common.result.Result;
import cn.edu.zzuli.common.result.ResultInfo;
import cn.edu.zzuli.model.entity.Points;
import cn.edu.zzuli.model.entity.User;
import cn.edu.zzuli.wechat.filter.NoAuth;
import cn.edu.zzuli.wechat.user.service.PointsService;
import cn.edu.zzuli.wechat.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user/sign")
@Api(tags = "签到接口")
public class PointsController {

    @Autowired
    private PointsService pointsService;

    @Autowired
    private UserService userService;


    @ApiOperation("点击签到")
    @GetMapping("in")
    public ResultInfo signIn(Integer uid, Integer week){
        Map<String, Object> res = pointsService.sign(uid,week);
        return Result.ok(res);
    }


    @ApiOperation("进入签到页面获得列表")
    @GetMapping("list")
    public ResultInfo signRes(Integer uid){
        Map<String, Object> res = pointsService.res(uid);
        return Result.ok(res);
    }


    @ApiOperation("将点券兑换为积分")
    @GetMapping("change")
    public ResultInfo changeSco(Integer score, Integer uid){
        pointsService.changeSco(score,uid);
        return Result.ok();
    }

    @ApiOperation("签到提醒 ")
    @GetMapping("remind")
    public void openRemind(HttpSession session){
        Integer uid = (Integer) session.getAttribute("uid");
        User user = new User();
        user.setUid(uid);
        user.setSignIn(1);
        userService.updateById(user);
    }

}
